<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Vote
 * @copyright  Copyright 2011 KEENONWEB LLC
 * @license    http://www.keenonweb.com/
 * @version    $Id: manage.tpl 2011-03-09 01:11:30 idris $
 * @author     Idris
 */
?>

<div class="headline">
  <h2>
    <?php echo $this->translate('Video Votings');?>
  </h2>
  <?php if( count($this->navigation) > 0 ): ?>
  <div class="tabs">
    <?php
        echo $this->navigation()
    ->menu()
    ->setContainer($this->navigation)
    ->render();
    ?>
  </div>
  <?php endif; ?>
</div>

<div class="layout_middle layout_vote_middle">

  <div class="kowcore-manage-container">
    <?php if ($this->paginator->getTotalItemCount() > 0): ?>
    <ul class="browse">
      <?php foreach( $this->paginator as $item ): ?>
        <li class="<?php echo $item->featured ? 'featured' : ''; ?>">
          <div class='photo'>
            <?php echo $this->htmlLink($item->getHref(), $this->itemPhoto($item, 'thumb.normal')); ?>
          </div>
          <div class='info'>
						<h3 class="title"><?php echo $this->htmlLink($item->getHref(), $item->getTitle()) ?></h3>
						<div class="clr"></div>
						<ul class="misc">
						<?php if ($item->category_id): ?>
							<li class="category"><?php echo $this->translate('Category: %s', $this->htmlLink($this->url(array('controller' => 'video', 'action' => 'manage', 'category' => $item->category_id), 'vote_general'), $item->category_name)); ?></li>
						<?php endif; ?>
						<?php if ($item->view_count): ?>
							<li class="views"><?php echo $this->translate(array('%s view', '%s views', $item->view_count), $item->view_count); ?></li>
						<?php endif; ?>
						<?php if ($item->participant_count): ?>
							<li class="participants"><?php echo $this->translate(array('%s participant', '%s participants', $item->participant_count), $item->participant_count); ?></li>
						<?php endif; ?>
						<?php if ($item->comment_count): ?>
							<li class="comments"><?php echo $this->translate(array('%s comment', '%s comments', $item->comment_count), $item->comment_count); ?></li>
						<?php endif; ?>
            <?php $likeCount = $item->likes()->getLikeCount(); if ($likeCount): ?>
							<li class="likes"><?php echo $this->translate(array('%s like', '%s likes', $likeCount), $likeCount); ?></li>
						<?php endif; ?>
						<?php if ($item->keywords): ?>
							<li class="tags"><?php echo $item->getTagLinks(); ?></li>
						<?php endif; ?>
						</ul>
              <?php if (!$item->isStarted(false)): ?>
              <p class='date options'>
                <?php echo $this->htmlLink($this->url(array('action' => 'edit', 'challenge_id' => $item->getIdentity()), 'vote_general'), '', array('class' => 'edit')); ?>
                <?php echo $this->htmlLink($this->url(array('action' => 'delete', 'format' => 'smoothbox', 'challenge_id' => $item->getIdentity()), 'vote_general'), '', array('class' => 'delete smoothbox')); ?>
              </p>
              <?php else: ?>
              <p class='date'>
                <?php echo $this->translate('Voting started'); ?>
              </p>
              <?php endif; ?>
						<div class="clr"></div>
            <p class='blurb'>
              <?php
                echo substr(strip_tags($item->getDescription()), 0, 350);
								if (strlen($item->getDescription())>349) echo "...";
							?>
            </p>
            <?php if (!$item->approved): ?>
              <div class="tip"><span><?php echo $this->translate('This voting is not approved yet. Please wait until administration will approve it.'); ?></span></div>
            <?php endif; ?>
						<p class="duration"><?php echo $this->translate('Started at %s lasts to %s', $this->timestamp(strtotime($item->starttime)), $this->timestamp(strtotime($item->endtime))); ?></p>
						<div class="clr"></div>
          </div>
					<div class="clr"></div>
        </li>
      <?php endforeach; ?>
    </ul>

    <?php else: ?>
    <div class="tip">
      <span>
        <?php echo $this->translate('Nobody has created a voting yet.');?>
        <?php if ($this->can_create): ?>
        <?php echo $this->translate('Be the first to %1$screate%2$s one!', '<a href="'.$this->url(array('action' => 'create', 'controller' => 'video'), 'vote_general', true).'">', '</a>'); ?>
        <?php endif; ?>
      </span>
    </div>
    <?php endif; ?>
    <div class="clr"></div>
  </div>
  
  <br />
  <?php echo $this->paginationControl($this->paginator, null, null); ?>
  
</div>

<script type="text/javascript">
  var pageAction = function(page) {
  $('page').value = page;
  $('filter_form').submit();
  }

  var tagAction = function(tag) {
  $('tag').value = tag;
  $('filter_form').submit();
  }

  var searchChallenges = function() {
  if (Browser.Engine.trident) {
  document.getElementById('filter_form').submit();
  } else {
  $('filter_form').submit();
  }
  }

</script>

<div class="layout_right layout_vote_right">
  <?php echo $this->form->render($this); ?>
</div>

<div class="clr"></div>